﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using System.Threading.Tasks;
using System.Threading;

namespace Microsoft.Samples.Kinect.WpfViewers
{
    public static  class StartCapture
    {
        public static bool StartMyCapture = false;
        public static event EventHandler GestureRecognized = delegate{};
        public static void OnGestureRecognized(){
            GestureRecognized(null, EventArgs.Empty);
        }
        public static void Start(Action<TimeSpan> invokePeriod, Action invokeFinish, int timeSeconds)
        {
            
            Task t = new Task(
                () =>
                {
                    DateTime dtNow = DateTime.Now;
                    while (DateTime.Now.Subtract(dtNow).TotalSeconds < timeSeconds)
                    {
                        Thread.Sleep(2 * 1000);
                        var ts = DateTime.Now.Subtract(dtNow);
                            if (invokePeriod != null)
                                invokePeriod(ts);
                            
                        
                    };

                    StartCapture.StartMyCapture = true;
                    if (invokeFinish != null)
                            invokeFinish();
                                        
                });
            t.Start();
        }
    }
}
